package com.woniu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.ExpenseDetail;
import com.woniu.entity.response.ResponseEntity;
import com.woniu.entity.vo.PageExpenseDetail;
import com.woniu.service.IExpenseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@RestController
@RequestMapping("/brain/expenseDetail")
public class ExpenseDetailController {
    @Autowired
    private IExpenseDetailService expenseDetailService;

    //已优化为多条件分页查询

    //查询全部
    @RequestMapping("/list")
    public ResponseEntity findAll(){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getAll();
        return  ResponseEntity.success(expenseDetails,"查询成功");
    }

    //根据UID分页查询
    @RequestMapping("/mylist")
    public ResponseEntity myListWithPage(@RequestBody PageExpenseDetail info){

        Page<ExpenseDetail> page = expenseDetailService.myListWithPage(info.getPageNum(),info.getPageSize(),info.getExpenseDetail().getUser().getUserId());
        return ResponseEntity.success(page.getRecords(),"查询成功");
    }


    //根据报销单号查询
    //EDID -->exp_detail_id
    @RequestMapping("/list/edid/{edid}")
    public ResponseEntity findByEdid(@PathVariable("edid") int edid){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getByEDId(edid);
        return  ResponseEntity.success(expenseDetails);
    }


    //根据报销类别号查询
    //EID -->exp_id
    @RequestMapping("/list/eid/{eid}")
    public ResponseEntity findByEid(@PathVariable("eid") int eid){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getByEid(eid);
        return  ResponseEntity.success(expenseDetails);
    }


    //根据银行账号查询
    //BID -->bank_id
    @RequestMapping("/list/bid/{bid}")
    public ResponseEntity findByBid(@PathVariable("bid") int bid){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getByEid(bid);
        return  ResponseEntity.success(expenseDetails);
    }

    //根据部门ID查询
    //DID -->dept_id
    @RequestMapping("/list/did/{did}")
    public ResponseEntity findByDid(@PathVariable("did") int did){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getByEid(did);
        return  ResponseEntity.success(expenseDetails);
    }

    //根据报销时间查询支持模糊查询
    //EDate -->exp_date
    @RequestMapping("/list/edate/{edate}")
    public ResponseEntity findByEDate(@PathVariable("edate") int edate){
        List<ExpenseDetail> expenseDetails = expenseDetailService.getByEid(edate);
        return  ResponseEntity.success(expenseDetails);
    }


    //添加报销单
    //EDetail-->Expense_Detail
    @RequestMapping("/add")
    public ResponseEntity addList(@RequestBody ExpenseDetail expenseDetail){
        expenseDetailService.addEDetail(expenseDetail);
        return  ResponseEntity.success(null,"添加成功");
    }

    //审批（未通过）
    //EDID -->exp_detail_id
    //EFBack -->expFeedback
    @RequestMapping("/unpass")
    public ResponseEntity unpass(@RequestBody ExpenseDetail expenseDetail){
        int edid = expenseDetail.getExpDetailId();
        String efback = expenseDetail.getExpFeedback();
        expenseDetailService.unpass(edid,efback);
        return  ResponseEntity.success(null,"审批成功");
    }

    //审批（未通过）
    //EDID -->exp_detail_id
    //EFBack -->expFeedback
    @RequestMapping("/pass")
    public ResponseEntity pass(@RequestBody ExpenseDetail expenseDetail){
        int edid = expenseDetail.getExpDetailId();
        String efback = expenseDetail.getExpFeedback();
        expenseDetailService.pass(edid,efback);
        return  ResponseEntity.success(null,"不予审批");
    }

    //多条件分页查询
    @RequestMapping("/list/byCondition")
    public ResponseEntity getByCondition(@RequestBody PageExpenseDetail info){
        Page<ExpenseDetail> page = expenseDetailService.getByConditionWithPage(info.getPageNum(), info.getPageSize(), info.getExpenseDetail());
        return ResponseEntity.success(page.getRecords(),"查询成功");
    }
}
